/**************************************************************************
 *  创建者：        hualei
 *  开始时间：   2018.09.28
 *  copyright:  (C) 深圳市华友高科有限公司
 *  修改说明：  (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 *
 ***************************************************************************
 *   LIFT 升降机构指令属性编辑视窗实现
 *
 ***************************************************************************/
#include "liftmechanisminstructionview.h"
#include "ui_liftmechanisminstructionview.h"
#include "../../programView/programview.h"

LiftMechanismInstructionView::LiftMechanismInstructionView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LiftMechanismInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void LiftMechanismInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void LiftMechanismInstructionView::getInput()
{

//    mechanismType = E_MECHANISM_GENERAL;
    timeOutValue = ui->TimeOut_Value_Edit->text().toInt();
    jmpLbValue = ui->JMP_LB_Edit->text().toInt();
    noteStr = ui->Note_Edit->text();
}

void LiftMechanismInstructionView::updateView()
{
    ui->Rise_RadioBtn->setChecked(false);
    ui->Down_RadioBtn->setChecked(false);
    ui->Rise_RadioBtn_middle->setChecked(false);
    ui->Down_RadioBtn_middle->setChecked(false);

    if(liftType == E_LIFT_RISE)
    {
        ui->Rise_RadioBtn->setChecked(true);
    }
    else if(liftType == E_LIFT_DOWN)
    {
        ui->Down_RadioBtn->setChecked(true);
    }
    else if(liftType == E_LIFT_RISE_MIDDLE)
    {
        ui->Rise_RadioBtn_middle->setChecked(true);
    }
    else if(liftType == E_LIFT_DOWN_MIDDLE)
    {
        ui->Down_RadioBtn_middle->setChecked(true);
    }


    ui->TimeOut_Value_Edit->setText(QString::number(timeOutValue));
    ui->JMP_LB_Edit->setText(QString::number(jmpLbValue));
    ui->Note_Edit->setText(noteStr);
}

void LiftMechanismInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/liftMechanismInstructionView.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);

}

void LiftMechanismInstructionView::on_Rise_RadioBtn_clicked()
{
    liftType = E_LIFT_RISE;
}

void LiftMechanismInstructionView::on_Down_RadioBtn_clicked()
{
    liftType = E_LIFT_DOWN;
}

void LiftMechanismInstructionView::on_clearNote_Btn_clicked()
{
    ui->Note_Edit->clear();
    emit cleanNoteSignal();
}

void LiftMechanismInstructionView::on_save_Btn_clicked()
{
    getInput();
    emit finishEditInstructionSignal();
    emit saveInstruction(instructionStr);
}

void LiftMechanismInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void LiftMechanismInstructionView::on_Rise_RadioBtn_middle_clicked()
{
    liftType = E_LIFT_RISE_MIDDLE;
}

void LiftMechanismInstructionView::on_Down_RadioBtn_middle_clicked()
{
    liftType = E_LIFT_DOWN_MIDDLE;
}
